Skip to content

Fix two normalize() collisions between structurally different resources - #406

Merged
benoit74 merged 1 commit into
mainfrom
benoit74/fix-normalize-collisions
Nov 17, 2026
Merged

benoit74 merged 1 commit into
mainfrom
benoit74/fix-normalize-collisions

Conversation

@benoit74

Copy link
Copy Markdown
Collaborator

Summary

Addresses the first item of #396's plan (the three normalize()/escape_dot_segments() fixes), for the two that are genuine content collisions with no acceptable workaround:

  • A percent-encoded / (%2F) in the path was decoded into a literal / by normalize(), making it indistinguishable from an actual path separator: /foo%2Fbar (one segment, containing a literal /) and /foo/bar (two segments) both normalized to the same ZIM path. It is now kept encoded (as %2F).
  • A literal _./_.. segment (already of the escaped form used for an actual ./.. dot-segment) was left untouched by escape_dot_segments(), colliding with the escaped form of an actual dot-segment. escape_dot_segments() now escapes such a segment with one more leading _, forming a ladder (. → _., literal _. → __., literal __. → ___., ...) that never collides across levels.

The third collision raised in #396 (+/%20/raw space in the query string all collapsing to the same stored space) is intentionally left as-is: all three are HTTP-query-string equivalent, and get_document_uri() already re-encodes the stored space back to %20 when building the actual rewritten URL, so no information that matters is lost.

A percent-encoded `/` (%2F) in the path was decoded into a literal `/`
by normalize(), making it indistinguishable from an actual path
separator, e.g. "/foo%2Fbar" (one segment) and "/foo/bar" (two
segments) both normalized to the same ZIM path. It is now kept
encoded (as %2F).

A literal `_.`/`_..` segment (already of the escaped form used for an
actual `.`/`..` dot-segment) was left untouched by
escape_dot_segments(), colliding with the escaped form of an actual
dot-segment, e.g. a literal "_." segment and an unresolved "."
dot-segment both normalized to "_.". escape_dot_segments() now escapes
such a segment with one more leading `_`, forming a ladder (`.` ->
`_.`, literal `_.` -> `__.`, literal `__.` -> `___.`, ...) that never
collides across levels.

The third collision raised in #396 (`+`/`%20`/raw space in the query
string all collapsing to the same stored space) is intentionally left
as-is: all three are HTTP-query-string equivalent, and
get_document_uri() already re-encodes the stored space back to %20
when building the actual rewritten URL, so no information that
matters is lost.
@benoit74 benoit74 self-assigned this Nov 17, 2026
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c04cbc0) to head (b852cc0).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #406   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           42        42           
  Lines         2954      2958    +4     
  Branches       453       453           
=========================================
+ Hits          2954      2958    +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@benoit74
benoit74 merged commit 3d2e4b2 into main Nov 17, 2026
10 checks passed
@benoit74
benoit74 deleted the benoit74/fix-normalize-collisions branch November 17, 2026 09:51
@benoit74 benoit74 added this to the 5.6.0 milestone Nov 20, 2026
@benoit74 benoit74 mentioned this pull request Nov 20, 2026
18 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant